home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Ham⁄GPS / SoftKiss.src.1.8 Folder / SoftKiss.src.1.8 / (unloved) / xsfk_notify.c < prev    next >
Text File  |  1992-02-20  |  6KB  |  276 lines

  1. /*
  2.  *
  3.  * mac mail check network checking module
  4.  * by Aaron Wohl (aw0g+@andrew.cmu.edu) jul 1990
  5.  * Carnegie-Mellon University
  6.  * Pittsburgh, PA 15213-3890
  7.  * (412)-268-5032
  8.  *
  9.  */
  10. #ifdef NYI
  11.  
  12. #include <string.h>
  13. #include "sfk_core.h"
  14. #include "sfk_notify.h"
  15. #include "sfk_core_private.h"
  16. #include "sfk_os_preserve.h"
  17. #include <SoundDvr.h>
  18. #include "sfk_config.h"
  19.  
  20. static note_vars nv;
  21.  
  22. /*
  23.  * rememer a private copy of text for use by the notification mgr
  24.  */
  25. LDEF(char *remember(char *text))
  26. {
  27.     static char buf[256];
  28.     int len=strlen(text);
  29.     char *dst=buf+1;
  30.     len=imax(0,imin(250,len));
  31.     strcpy(buf+1,"* ");
  32.     dst+=strlen(dst);
  33.     if(len!=0) {
  34.         memcpy(dst,text,len);
  35.         dst+=len;
  36.         *dst= 0;
  37.     }
  38.     buf[0]=strlen(buf+1);
  39.     return buf;
  40. }
  41.  
  42. /*
  43.  * get and detach a resource if there is space
  44.  */
  45. LDEF(char **get_and_detach(long reskind,int resid,int *goterror))
  46. {
  47.     char **result;
  48.     long res_size;
  49.     result=GetResource(reskind,resid);
  50.     SetResLoad(TRUE);
  51.     if(result==0) {
  52.           *goterror= TRUE;
  53.             strcpy(sfk_gl.cs.sfk_text_state,
  54.                 "New MailCheck configuration set, but can't find your sound resource.");
  55.         return 0;
  56.     }
  57.     res_size=SizeResource(result);
  58. #ifdef XXXX
  59. Multifinder seems to expand the system heap when it wants so this isn't accurate.
  60.     if(res_size>40) {
  61.         long max_free=MaxBlock();
  62.         if((max_free-res_size)<SYS_RESERVE) {
  63.           *goterror= TRUE;
  64.           ReleaseResource(result);
  65.             strcpy(sfk_gl.cs.sfk_text_state,
  66.                 "New MailCheck configuration set, but not enough space for sound in system heap.");
  67.           return 0;    
  68.         }
  69.     }
  70. #endif
  71.     LoadResource(result);
  72.     if(ResError()!=0) {
  73.         ReleaseResource(result);
  74.         return 0;
  75.     }
  76.     DetachResource(result);
  77.     return result;
  78. }
  79.  
  80. /*
  81.  * get and detach a resource into the system zone if there is space
  82.  */
  83. LDEF(char **get_res_into_sys(long reskind,int resid,int *goterror))
  84. {
  85.     register char **result;
  86.     result=(char **)OSP_protected_call(OSP_sys|OSP_noload,get_and_detach,reskind,resid,goterror);
  87.     return result;
  88. }
  89.  
  90. LDEF(void sfk_uninit_sound(void))
  91. {
  92.     if(nv.snd_handle!=0) {
  93.         DisposHandle(nv.snd_handle);
  94.         nv.snd_handle=0;
  95.     }
  96. }
  97.  
  98. int sfk_note_sound_init(int new_sound_res_num)
  99. {
  100.     int got_error=0;
  101.     if(nv.sicn_handle[sfk_note_mail]==0)
  102.       nv.sicn_handle[sfk_note_mail]=get_res_into_sys('SICN',-4064,&got_error);
  103.     if(nv.sicn_handle[sfk_note_error]==0)
  104.       nv.sicn_handle[sfk_note_error]=get_res_into_sys('SICN',-4063,&got_error);
  105.     if(new_sound_res_num!=sfk_gl.cs.sfk_sound_id) {
  106.       sfk_uninit_sound();
  107.       if(gFLSET(MCS_nsound)&&(nv.snd_handle==0))
  108.         nv.snd_handle=get_res_into_sys('snd ',new_sound_res_num,&got_error);
  109.     }
  110.     sfk_gl.cs.sfk_sound_id=new_sound_res_num;
  111.     return got_error;
  112. }
  113.  
  114. /*
  115.  * remove a notification event
  116.  */
  117. LDEF(pascal void notify_done_routine(struct NMRec *arec))
  118. {
  119.     if(arec==0)
  120.         DebugStr("pMailCheck nremove NIL");
  121.     if(arec->nmRefCon==0)return;
  122.     NMRemove(((QElemPtr)arec));
  123.     arec->nmRefCon=0;
  124. }
  125.  
  126. /*
  127.  * install a notification event
  128.  */
  129. LDEF(int sfk_note_install(
  130.     char *text,
  131.     Handle sound,
  132.     Handle sicn,
  133.     struct NMRec *arec))
  134. {
  135.     int err;
  136.  
  137.     if(arec==0)
  138.         DebugStr("pMailCheck ninstall NIL");
  139.     if(!gFLSET(MCS_nblink))
  140.         sicn=0;
  141.     if(!gFLSET(MCS_nsound)||(SdVolume==0))
  142.         sound=0;
  143.     if(gFLSET(MCS_nsound)&&(SdVolume==0))
  144.         SysBeep(30);            /*flash the title bar if can't speak*/
  145.  
  146.     if(arec->nmRefCon!=0) {
  147.         if((sound==0)&&(text==0)&&(sicn==arec->nmSIcon))
  148.             return;            /*already doing this*/
  149.         notify_done_routine(arec);
  150.     }
  151.  
  152.     if((sound==0)&&(text==0)&&(sicn==0))
  153.         return;
  154.  
  155.     memset(arec,0,sizeof(*arec));
  156.     arec->qType=nmType;
  157.     arec->nmSound=sound;
  158.     arec->nmStr=(StringPtr)text;
  159.     arec->nmSIcon=sicn;
  160.     if(sicn==0)
  161.         arec->nmResp= ((ProcPtr)¬ify_done_routine);
  162.     arec->nmRefCon=1;
  163.  
  164.     err=NMInstall(((QElemPtr)arec));
  165.     if(err!=0) {
  166.         arec->nmRefCon=0;
  167.         SysBeep(30);
  168.         return FALSE;
  169.     }
  170.     return TRUE;
  171. }
  172.  
  173. /*
  174.  * insert a notify alert into the system queue
  175.  */
  176. LDEF(void sfk_note_post(Handle sound))
  177. {
  178.     char *text=0;
  179.     if(sound==0)
  180.         sound=((Handle)-1);
  181.     if(!gFLSET(MCS_nsound))
  182.         sound=0;
  183.  
  184.     if(gFLSET(MCS_npost)) {
  185.         textify_error();
  186.         text=remember(sfk_gl.cs.sfk_text_state);
  187.     }
  188.  
  189.     sfk_note_install(text,sound,0L,&nv.post_note_rec);
  190. }
  191.  
  192. LDEF(void remind_error(void))
  193. {
  194.   sfk_note_install(0L,0L,
  195.     nv.sicn_handle[sfk_note_error],
  196.     &nv.blink_note_rec);
  197.   sfk_note_post(0);
  198.   set_event(EV_remind,remind_error,sfk_gl.cs.sfk_remind_time);
  199. }
  200.  
  201. LDEF(void remind_mail(void))
  202. {
  203.   sfk_note_install(0L,0L,
  204.     nv.sicn_handle[sfk_note_mail],
  205.     &nv.blink_note_rec);
  206.   sfk_note_post(nv.snd_handle);
  207.   set_event(EV_remind,remind_mail,sfk_gl.cs.sfk_remind_time);
  208. }
  209.  
  210. void set_event(int evnum,void (*dowhat)(),long dowhen)
  211. {
  212.     register sfk_event_pt anev= &sfk_gl.cps.ev[evnum];
  213.     anev->ev_time=dowhen+TickCount();
  214.     anev->ev_event=dowhat;
  215. }
  216.  
  217. /*
  218.  * uninitialize the notification system
  219.  */
  220. void sfk_note_done(void)
  221. {
  222.     notify_done_routine(&nv.post_note_rec);
  223.     notify_done_routine(&nv.blink_note_rec);
  224.     set_event(EV_remind,EV_NOTHING,0);
  225.     set_event(EV_error,EV_NOTHING,0);
  226. }
  227.  
  228. void sfk_note_new_error(void)
  229. {
  230.   if(sfk_gl.cps.ev[EV_remind].ev_event==remind_error)
  231.     return;
  232.   set_event(EV_remind,remind_error,0);
  233. }
  234.  
  235. void sfk_note_old_mail(void)
  236. {
  237.   if(sfk_gl.cps.ev[EV_remind].ev_event!=remind_mail)
  238.       set_event(EV_remind,remind_mail,MIN_REMIND);
  239. }
  240.  
  241. void sfk_note_no_error(void)
  242. {
  243.   sfk_gl.cs.sfk_last_err_kind=MCE_NOERRR;
  244.   if(sfk_gl.cps.ev[EV_remind].ev_event==remind_error)
  245.     sfk_note_done();
  246. }
  247.  
  248. void sfk_note_new_mail(void)
  249. {
  250.   set_event(EV_remind,remind_mail,0);
  251. }
  252.  
  253. void sfk_note_no_mail(void)
  254. {
  255.   if(sfk_gl.cps.ev[EV_remind].ev_event==remind_mail)
  256.     sfk_note_done();
  257. }
  258.  
  259. void sfk_note_init(void)
  260. {
  261.     memset(&nv,0,sizeof(nv));
  262. }
  263.  
  264. void sfk_note_uninit()
  265. {
  266.     register int i;
  267.     sfk_note_done();
  268.     for(i=0;i<sfk_note_kinds;i++)
  269.       if(nv.sicn_handle[i]!=0) {
  270.         DisposHandle(nv.sicn_handle[i]);
  271.         nv.sicn_handle[i]=0;
  272.       }
  273.     sfk_uninit_sound();
  274.     sfk_note_init();
  275. }
  276. #endif NYI